package rs.webnet.android.kamere;

import android.app.Activity;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class PointActivity extends Activity {
	private RelativeLayout holder;
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.point_layout);
        Bundle b=new Bundle();
		b=getIntent().getExtras();
		
		holder = (RelativeLayout)findViewById(R.id.point_info_holder);
		Animation slideDown = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_in_from_top);
		holder.startAnimation(slideDown);
		
        String stitle=b.getString("title");
        String sdesc=b.getString("description");
        String simage=b.getString("image");
        
        TextView title=(TextView)findViewById(R.id.title);
        ImageView image=(ImageView)findViewById(R.id.image);
        TextView description=(TextView)findViewById(R.id.description);
       
        title.setText(stitle);
        description.setText(sdesc);
        
        if(simage.contains("odron")){
        	image.setImageResource(R.drawable.odron_big);
        }else if(simage.contains("opasnost")){
        	image.setImageResource(R.drawable.opasnost_big);
        }else if(simage.contains("radovi")){
        	image.setImageResource(R.drawable.radovi_big);
        }else if(simage.contains("zabrana-teretna")){
        	image.setImageResource(R.drawable.zabrana_teretna_big);
        }else if(simage.contains("zabrana")){
        	image.setImageResource(R.drawable.zabrana_big);
        }else if(simage.contains("info")){
        	Log.d("d","Treba da povuce info ");
        	image.setImageResource(R.drawable.info_big);
        }
	}
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
	    if ((keyCode == KeyEvent.KEYCODE_BACK)) {
	        Log.d(this.getClass().getName(), "back button pressed");
			holder = (RelativeLayout)findViewById(R.id.point_info_holder);
			Animation slideDown = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_out_to_top);
			holder.startAnimation(slideDown);
			new Timer().execute();
	    }
	    return false;//super.onKeyDown(keyCode, event);
	}
	private class Timer extends AsyncTask<Void, Void, Boolean>{
		@Override
		protected Boolean doInBackground(Void... params) {
			try {
				Thread.sleep(300);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			return true;
		}
		@Override
		protected void onPostExecute(Boolean result) {
			PointActivity.this.finish();
	     }
		
	}
}
